/**
 * DDALine
 * Zhifeng Liang
 * liangzhf@gmail.com
 * 
 * 
 */

package feng.nbic.line;

import java.awt.*;

import javax.swing.*;

public class DDALine extends JApplet {

	private static final long serialVersionUID = 1L;

	public void drawDDALine(int x0, int y0, int x1, int y1, Graphics g) {

		int x, k, dx, dy, t;
		float y, m;
		dx = x1 - x0;
		dy = y1 - y0;
		x = x0;
		y = y0;
		m = (float) dy / dx;
		for (k = 0; k < dx; k++) {

			t =Math.round(y);
			// g.fillRect(x, t, 1, 1);
			g.drawLine(x, t, x+3, t);
			x++;
			y += m;
		}

	}

	public void paint(Graphics g) {

		g.setColor(Color.red);
		drawDDALine(10, 10, 100, 100, g);
		drawDDALine(100, 100, 190, 10, g);

	}

}
